<template>
    <div class="app-container">
        <el-breadcrumb separator="/" class="breadcrumb2">
            <el-breadcrumb-item :to="{ path: '/userrightlink2/userrightlink21' }">组织绑定</el-breadcrumb-item>
        </el-breadcrumb>
        <!--当前权限等级-->
        <el-card class="right">
            <div>
                <i class="el-icon-suitcase"></i>
                <span >当前权限等级：</span>
                <el-tag>{{nowRight}}</el-tag>
            </div>
        </el-card>
        <!--绑定的上级-->
        <el-card class="righttable">
            <i class="el-icon-star-off"></i>
            <span>绑定的上级</span>
            <div style="width:300px;margin:0 auto;">
            <span style="color: gray;">学校管理员没有绑定的上级</span>
            </div>
        </el-card>
        
        <!--绑定的下级-->
        <el-card class="righttable">
            <i class="el-icon-user"></i>
            <span>绑定的下级</span>
            <el-table
                :data="bindDown"
                style="width: 100%; margin-top:20px;"
                fit 
                border
                stripe
            >     
                <el-table-column
                prop="teacherName"
                label="组织管理员姓名"
                min-width="100"
                align="center">
                </el-table-column>
                <el-table-column
                prop="groupName"
                label="管理单位名称"
                min-width="100"
                align="center">
                </el-table-column>
                <el-table-column
                prop="status"
                label="绑定状态"
                min-width="100"
                align="center">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.status===1">已绑定</el-tag>
                    <el-tag type="warning" v-else-if="scope.row.status===0">待审核</el-tag>
                </template>
                </el-table-column>
                <el-table-column
                label="操作"
                min-width="100"
                align="center">
                <template slot-scope="scope">
                    <div v-if="scope.row.status===1">
                        <el-button  type="danger" size="small" @click="closedown(scope.row)">解绑</el-button>
                    </div>
                    <div v-else>
                    <el-button  type="success" size="small" @click="agreedown(scope.row)">批准</el-button>
                    <el-button  type="warning" size="small" @click="rejectdown(scope.row)">驳回</el-button>
                    </div>
                </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
            <el-pagination
                background
                @size-change="handleSizeChange2"
                @current-change="handleCurrentChange2"
                layout="total, sizes, prev, pager, next,jumper"
                :current-page.sync="formInline2.pageNum"
                :page-size="formInline2.pageSize"
                :page-sizes="[5, 10, 15]"
                :total="total2"
            ></el-pagination>
            </div>
        </el-card>
    </div>
</template>

<script>
import qs from 'qs'
export default {
    data(){
        return{
            
            nowRight:'',
            tid: null,
            uid:'',
            //下级单位
            bindDown:[],
            //下级单位列表 //分页
            formInline2: {
                university: '',
                academy: '',
                name: '',
                pageNum: 1,
                pageSize: 5,
            },
            tid2: null,
            total2: 0,
        }
    },
    created(){
        this.uid=sessionStorage.getItem('uid')
        this.getRoleofZuzhi()
        this.getDownList()
    },
    methods:{
        //同意下级绑定
        async agreedown(mydata){
            const{ data:res }=await this.$http.post('/authority/handleApply',qs.stringify({
                applyId :mydata.recordId,
                applyType :2,
                handleType :1,
                rejectReason :'无'
            }))
            if(res.code==200){
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
                this.getDownList()
            }
        },
        //拒绝下级绑定
        async rejectdown(mydata){
            const{data:res}=await this.$http.post('/authority/handleApply',qs.stringify({
                applyId :mydata.recordId,
                applyType :2,
                handleType :0,
                rejectReason :'无'
            }))
            if(res.code==200){
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
                this.getDownList()
            }
        },
        //解除下级绑定
        async closedown(mydata){
            const{data:res}=await this.$http.post('/authority/cancelBind',qs.stringify({
                groupId  :mydata.groupId,
                uid: mydata.teacherUid
            }))
            if(res.code==200){
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
                this.getDownList()
            }
        },
        //获取绑定的下级记录
        async getDownList(){
            const{data:res}=await this.$http.get('/authority/getBindApplyRecord',{
                params:{
                    groupId:sessionStorage.getItem('groupId'),
                    pageNum:this.formInline2.pageNum,
                    pageSize :this.formInline2.pageSize
                }
            })
            if(res!=null){
                this.total2=res.data.total;
                this.bindDown=res.data.list
            }
        },
        


        //获取当前角色
        async getRoleofZuzhi(){
            const {data:res} = await this.$http.get('/authority/getOwnAuth',{
                params:{
                    uid:this.uid
                }
            })
            if(res!=null){
                sessionStorage.setItem("groupId",res.data.adminGroupEntity.id)
                this.nowRight=res.data.adminGroupEntity.groupName+"管理员"
            }
        },
        // 实现分页
        // 更改了每页大小
        handleSizeChange2(val) {
            this.formInline2.pageNum = 1
            this.formInline2.pageSize = val
            this.getDownList()
        },
        // 更改了第几页
        handleCurrentChange2(val) {
            this.formInline2.pageNum = val
            this.getDownList()
        },
        handleClick(){

        },
        handleClose(){

        },
        handleChange(){},
    }
}
</script>

<style scoped>

</style>